package com.david.shortcuts

import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        registerWidgetReceiver()

        findViewById<View>(R.id.test).setOnClickListener {
//            val cityTrafficQr = Intent(Intent.ACTION_VIEW, Uri.parse("alipays://platformapi/startapp?saId=10000007"))
//            startActivity(cityTrafficQr)
//            ShortCutsProxyService.startPage(applicationContext, "alipays://platformapi/startapp?saId=10000007")
            ShortCutsProxyService.startPage(applicationContext, "weixin://dl/scanner")
        }

    }

    private fun registerWidgetReceiver() {
        val receiver = ShortCutsWidget()
        val filter = IntentFilter()
        filter.addAction(ShortCutsWidget.PANEL_VIEW_CLICK)
        filter.addAction(ShortCutsWidget.COLLECTION_VIEW_ACTION)
        filter.addAction(ShortCutsWidget.REFRESH_WIDGET)
        registerReceiver(receiver, filter)
    }


    /**
     * 用代码去开启管理员
     */
    fun openAdmin(view: View?) {
        // 创建一个Intent
        val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
        // 我要激活谁
        val mDeviceAdminSample = ComponentName(this, MyAdmin::class.java)
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample)
        // 劝说用户开启管理员权限
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "哥们开启我可以一键锁屏，你的按钮就不会经常失灵")
        startActivity(intent)
    }
}